package com.uflower.search.controller;

import com.uflower.common.to.CategoryEntity;
import com.uflower.search.feign.ProductFeignService;
import com.uflower.search.service.EsProductService;
import com.uflower.search.service.SearchService;
import com.uflower.search.service.impl.SearchServiceImpl;
import com.uflower.search.vo.SearchParams;
import com.uflower.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//处理检索请求
// http://localhost:88/api/search/product/list
@Controller
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchServiceImpl searchService;
    @Autowired
    ProductFeignService productFeignService;
    @RequestMapping("/product/list")
    public String search(SearchParams params, Model model){
        SearchResult searchResult = searchService.searchInEs(params);
        model.addAttribute("result",searchResult);
        //searchService.buildSearchRequest(params);
        //System.out.println(searchService.buildSearchRequest(params));
      return "search";
  }
    @RequestMapping("/product/default")
    public String search1(SearchParams params, Model model){
        SearchResult searchResult = searchService.searchInEs(params);
        model.addAttribute("result",searchResult);
        List<CategoryEntity> level1catalog = productFeignService.getLevel1catalog();
        model.addAttribute("categorys",level1catalog);
        return "default";
    }
    @RequestMapping("/search")
    public String searchPage(){
        return "search";
    }

}
